import numpy as np
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt

# 生成示例数据
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])

# 创建PCA模型并拟合数据
pca = PCA(n_components=2)
X_r = pca.fit_transform(X)

# 绘制结果
plt.scatter(X_r[:, 0], X_r[:, 1])
plt.title("PCA Example")
plt.xlabel("Principal Component 1")
plt.ylabel("Principal Component 2")
plt.show()